package com.zqcy.workbench.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zqcy.workbench.R;
import com.zqcy.workbench.bean.TabConfiguration;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * 全部应用适配器
 */
public class AllTabAdapter extends BaseQuickAdapter<TabConfiguration, BaseViewHolder> {
    private Context context;
    private boolean isEdit;

    public AllTabAdapter(Context context, List<TabConfiguration> data, boolean isEdit) {
        super(R.layout.item_tab_configuration, data);
        this.context = context;
        this.isEdit = isEdit;
    }

    @Override
    protected void convert(@NotNull BaseViewHolder helper, TabConfiguration item) {
        RelativeLayout layout = helper.getView(R.id.tab_configuration_layout);
        ImageView imageView = helper.getView(R.id.tab_configuration_select);
        if (isEdit) {
            imageView.setVisibility(View.VISIBLE);
            imageView.setBackgroundResource(item.isAdd() ? R.mipmap.tab_select_true : R.mipmap.tab_select_false);
            layout.setBackgroundColor(context.getResources().getColor(R.color.f7f8f9));
        } else {
            imageView.setVisibility(View.GONE);
            layout.setBackgroundColor(context.getResources().getColor(R.color.white));
        }
        helper.setText(R.id.tab_configuration_text, context.getResources().getString(item.getTabName()));
        helper.getView(R.id.tab_configuration_img).setBackgroundResource(item.getTabIcon());
    }
}
